import Vue from 'vue';
import VueRouter from 'vue-router';
import LayOut from '@/views/layout/LayOut';

VueRouter.prototype.isBack = true;

VueRouter.prototype.goBack = function () {
  this.isBack = true;
  window.history.go(-1);
};
Vue.use(VueRouter);

export const constantRouterMap = [
  {
    path: '/',
    name: 'login',
    component: () => import('@/views/login/LoginView')
  },
  // 首页
  {
    path: '/home',
    component: LayOut,
    redirect: { path: '/home/HomeView' },
    children: [
      {
        path: 'HomeView',
        name: 'home',
        component: () => import('@/views/home/HomeView')
      },
      {
        path: 'SubjectInfo',
        name: 'subjectinfo',
        component: () => import('@/components/BarSubjectInfo')
      },
      {
        path: 'writeRemark',
        name: 'writeRemarkHome',
        component: () => import('@/views/official/OfficialWriteRemark')
      },
      {
        path: 'SubjectSearch',
        name: 'subjectSearch',
        component: () => import('@/views/home/components/subjectSearch')
      },
      {
        path: 'BestBarer',
        name: 'bestBarer',
        component: () => import('@/views/home/components/bestBarer')
      },
      {
        path: 'SubjectWrite',
        name: 'subjectWrite',
        component: () => import('@/views/home/components/subjectWrite')
      }
    ]
  },
  // 游乐园
  {
    path: '/amusement',
    component: LayOut,
    redirect: { path: '/amusement/AmusementView' },
    children: [
      {
        path: 'AmusementView',
        name: 'amusement',
        component: () => import('@/views/amusement/AmusementView')
      }
    ]
  },
  // 官方
  {
    path: '/official',
    component: LayOut,
    redirect: { path: '/official/OfficialView' },
    children: [
      {
        path: 'OfficialView',
        name: 'official',
        component: () => import('@/views/official/OfficialView')
      },
      {
        path: 'OfficialWriteRemark',
        name: 'writeRemark',
        component: () => import('@/views/official/OfficialWriteRemark')
      }
    ]
  },
  // 杠题广场
  {
    path: '/square',
    component: LayOut,
    redirect: { path: '/square/SquareView' },
    children: [
      {
        path: 'SquareView',
        name: 'square',
        component: () => import('@/views/square/SquareView')
      },
      {
        path: 'SquareList',
        name: 'squareList',
        component: () => import('@/views/square/components/SquareList')
      }
    ]
  },
  // 个人中心
  {
    path: '/personal',
    component: LayOut,
    redirect: { path: '/personal/PersonalView' },
    children: [
      {
        path: 'PersonalView',
        name: 'personal',
        component: () => import('@/views/personal/PersonalView')
      },
      {
        path: 'PersonalInfo',
        name: 'personalInfo',
        component: () => import('@/views/personal/PersonalInfo')
      },
      {
        path: 'PersonalMessage',
        name: 'personalMessage',
        component: () => import('@/views/personal/PersonalMessage')
      }
    ]
  }
];

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};


const router = new VueRouter({
  // mode: 'history',
  // base: process.env.BASE_URL,
  // routes,
  linkActiveClass: 'is-active',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: constantRouterMap
});

export default router;
